package com.leyantech.ecp.agenx.dispatcher.codec;

import io.vertx.core.json.JsonObject;
import org.apache.commons.lang3.StringUtils;

/**
 * @author eahau, {@literal <eahau@foxmail.com>}
 * @date 2022-11-15.
 */
public class PlainMessageEncoder implements ClientMessageEncoder {

  @Override
  public JsonObject encode(JsonObject out) {
    // 示例代码，以后需要加密可实现 ClientMessageDecoder
    final JsonObject header = out.getJsonObject("header");
    JsonObject body = out.getJsonObject("body");
    final String compression = header.getString("compression");
    if (StringUtils.isNotEmpty(compression)) {
      // 将解码/解密 后的消息重新填充到 body 字段
      // body = coding;
      out.put("body", body);
    }
    // do nothing
    return out;
  }

}
